<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
<meta name="viewport"
      content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">

    <meta name="author" content="Liux">





<title>使用 pypiserver 架设私有的pypi服务器 | 爱羊羊，爱生活。</title>



    <link rel="icon" href="/favicon.ico">




    <!-- stylesheets list from _config.yml -->
    
    <link rel="stylesheet" href="/css/style.css">
    



    <!-- scripts list from _config.yml -->
    
    <script src="/js/script.js"></script>
    
    <script src="/js/tocbot.min.js"></script>
    



    
    
        
    


</head>
<body>
    <div class="wrapper ">
        <header>
    <nav class="navbar">
        <div class="container">
            <div class="navbar-header header-logo">

<a href="/">卷首</a>

</div>

            <div class="menu navbar-right">
                
                    <a class="menu-item" href="/archives">文章</a>
                
                    <a class="menu-item" href="/category">分类</a>
                
                    <a class="menu-item" href="/tag">标签</a>
                
            </div>

        </div>
    </nav>

    
    <nav class="navbar-mobile" id="nav-mobile">
        <div class="container">
            <div class="navbar-header">
                <div>
                    <a href="/">卷首</a><a id="mobile-toggle-theme">·&nbsp;Light</a>
                </div>
                <div class="menu-toggle" onclick="mobileBtn()">&#9776; Menu</div>
            </div>
            <div class="menu" id="mobile-menu">
                
                    <a class="menu-item" href="/archives">文章</a>
                
                    <a class="menu-item" href="/category">分类</a>
                
                    <a class="menu-item" href="/tag">标签</a>
                
            </div>
        </div>
    </nav>

</header>
<script>
    var mobileBtn = function f() {
        var toggleMenu = document.getElementsByClassName("menu-toggle")[0];
        var mobileMenu = document.getElementById("mobile-menu");
        if(toggleMenu.classList.contains("active")){
           toggleMenu.classList.remove("active")
            mobileMenu.classList.remove("active")
        }else{
            toggleMenu.classList.add("active")
            mobileMenu.classList.add("active")
        }
    }
</script>

	<div class="main">
            <div class="container">
    
    
        <div class="post-toc">
    <div class="tocbot-list">
    </div>
    <div class="tocbot-list-menu">
        <a class="tocbot-toc-expand" onclick="expand_toc()">展开</a>
        <a onclick="go_top()">到顶</a>
        <a onclick="go_bottom()">到底</a>
    </div>
</div>

<script>
    document.ready(
        function () {
            tocbot.init({
                tocSelector: '.tocbot-list',
                contentSelector: '.post-content',
                headingSelector: 'h1, h2, h3, h4, h5',
                collapseDepth: 1,
                orderedList: false,
                scrollSmooth: true,
            })
        }
    )

    function expand_toc() {
        var b = document.querySelector(".tocbot-toc-expand");
        tocbot.init({
            tocSelector: '.tocbot-list',
            contentSelector: '.post-content',
            headingSelector: 'h1, h2, h3, h4, h5',
            collapseDepth: 6,
            orderedList: false,
            scrollSmooth: true,
        });
        b.setAttribute("onclick", "collapse_toc()");
        b.innerHTML = "收起"
    }

    function collapse_toc() {
        var b = document.querySelector(".tocbot-toc-expand");
        tocbot.init({
            tocSelector: '.tocbot-list',
            contentSelector: '.post-content',
            headingSelector: 'h1, h2, h3, h4, h5',
            collapseDepth: 1,
            orderedList: false,
            scrollSmooth: true,
        });
        b.setAttribute("onclick", "expand_toc()");
        b.innerHTML = "展开"
    }

    function go_top() {
        window.scrollTo(0, 0);
    }

    function go_bottom() {
        window.scrollTo(0, document.body.scrollHeight);
    }

</script>

    

    
    <article class="post-wrap">
        <header class="post-header">
            <h1 class="post-title">使用 pypiserver 架设私有的pypi服务器</h1>
            
                <div class="post-meta">
                    
                        <span class="post-time">
                        <a href="#">2019-12-27&nbsp;&nbsp;11:20:00</a>
                        </span>
                    
                    
                </div>
            
        </header>

        <section class="post-tags">
            <div>
                <span class="tag">
                    
                    
                        <a href="/tags/python/"> python</a>
                    
                        <a href="/tags/pypi/"> pypi</a>
                    
                        <a href="/tags/pypiserver/"> pypiserver</a>
                    
                        
                </span>
            </div>
        </section>

        <div class="post-content">
            <h2 id="1、关于pipyserver"><a href="#1、关于pipyserver" class="headerlink" title="1、关于pipyserver"></a>1、关于pipyserver</h2><p>因为单位的内网与互联网物理隔离，无法访问官方的PyPI，平时做python开发需要添加包非常不方便，虽然也可将包下载到本地，通过<code>pip</code>安装，但无法多机多人共享。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">(venv)$ pip3 install /path/to/mypkgs/one.whl</span><br></pre></td></tr></table></figure>

<p>于是在网上找了一些资料，发现有不少架设私有pypi服务的工具：</p>
<p><a href="https://wiki.python.org/moin/PyPiImplementations/" target="_blank" rel="noopener"><strong>这里是官方的推荐列表</strong></a></p>
<p>经过对比，我选择了<code>pypiserver</code>,官方对其介绍如下：</p>
<blockquote>
<p>pypiserver is a minimal PyPI compatible server for pip or easy_install. It is based on bottle and serves packages from regular directories. Wheels, bdists, eggs and accompanying PGP-signatures can be uploaded either with pip, setuptools, twine, pypi-uploader, or simply copied with scp.</p>
</blockquote>
<p>意思就是：</p>
<blockquote>
<p><code>pypiserver</code> 是用于<code>pip</code> 和 <code>easy_install</code> 的迷你PyPI兼容服务器，基于<code>bottle</code> 并将包直接存储在文件系统目录中，也支持通过<code>pip</code>,<code>setuptools</code>,<code>twine</code>,<code>pypi-uploader</code>或者简单的scp命令向服务器上传Whells, bdists,eggs等各种格式的包以及相关PGP签名。</p>
</blockquote>
<p>搭建步骤非常简单：</p>
<h2 id="2-安装"><a href="#2-安装" class="headerlink" title="2.安装"></a>2.安装</h2><p>安装非常简单，如果能接互联网，则使用<code>pip3</code>安装</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">$</span><span class="bash"> pip3 install pypiserver</span></span><br></pre></td></tr></table></figure>

<p>如果不能接，先找个互联网电脑下载，然后把安装包复制到要安装的服务器中。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ pip3 download pypiserver</span><br></pre></td></tr></table></figure>





<h2 id="3-运行-pypiserver-服务"><a href="#3-运行-pypiserver-服务" class="headerlink" title="3.运行 pypiserver 服务"></a>3.运行 <strong>pypiserver</strong> 服务</h2><ul>
<li><p>建一个目录，用于放各种包</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ mkdir ~/pipy-pkgs</span><br></pre></td></tr></table></figure>



</li>
</ul>
<ul>
<li><p>将你的包复制到<code>~/pipy-pkgs</code> 下，然后运行服务</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ pypi-server -p 8080 ~/pipy-pkgs &amp;</span><br></pre></td></tr></table></figure>

<p>注意：<code>pypiserver</code>安装好后，<code>pypi-server</code>脚本一般位于<code>~/.local/bin</code>目录。</p>
</li>
</ul>
<h2 id="4-在客户机上访问"><a href="#4-在客户机上访问" class="headerlink" title="4.在客户机上访问"></a>4.在客户机上访问</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"><span class="comment"># 安装包</span></span></span><br><span class="line">pip install --extra-index-url http://localhost:8080/simple/ ...</span><br><span class="line">pip install --extra-index-url http://localhost:8080</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"><span class="comment"># 检索可用的包</span></span></span><br><span class="line">pip search --index http://localhost:8080 ...</span><br></pre></td></tr></table></figure>



<h2 id="5-配置客户机-pip"><a href="#5-配置客户机-pip" class="headerlink" title="5.配置客户机 pip"></a>5.配置客户机 pip</h2><p>在linux上，可以通过编辑<code>~/.pip/pip.conf</code>文件，设定一次性 <code>pip</code>的源:</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[global]</span><br><span class="line">extra-index-url = http://localhost:8080/simple/</span><br></pre></td></tr></table></figure>



<p>更多高级用法，请参考 <a href="https://pypi.org/project/pypiserver/" target="_blank" rel="noopener"><strong>官方主页</strong></a></p>

        </div>

        
            <section class="post-copyright">
                
                    <p class="copyright-item">
                        <span>文章作者:</span>
                        <span>Liux</span>
                    </p>
                
                
                
                    <p class="copyright-item">
                        <span>许可方式:</span>
                        <span>Copyright (c) 2019 <a href="http://creativecommons.org/licenses/by-nc/4.0/" target="_blank" rel="noopener">CC-BY-NC-4.0</a> LICENSE</span>
                    </p>
                
                

            </section>
        

        <section class="post-nav">
            
                <a class="prev" rel="prev" href="/2020/01/07/Linux%E7%B3%BB%E7%BB%9F%E4%BB%BB%E5%8A%A1%E5%92%8C%E8%BF%9B%E7%A8%8B%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/">Linux系统任务和进程常用操作</a>
            
            
            <a class="next" rel="next" href="/2019/11/20/linux-system-logs-and-the-syslog-standard/">Linux的日志系统简介</a>
            
            <a class="back" href="javascript:window.history.back();">退回</a>
        </section>
    </article>
</div>

        </div>
        <footer id="footer" class="footer">
    <div class="copyright">
        <span>© Liux | Powered by <a href="https://hexo.io" target="_blank">Hexo</a></span>
    </div>
</footer>

    </div>
</body>
</html>
